// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.network;

import java.io.File;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Scanner;
import se.krka.kahlua.vm.KahluaTable;
import se.krka.kahlua.vm.KahluaTableIterator;
import zombie.core.Core;
import zombie.core.secure.PZcrypt;
import zombie.core.znet.SteamUtils;
import zombie.debug.DebugLog;
import zombie.debug.LogSeverity;
import zombie.util.PZSQLUtils;

public class ServerWorldDatabase {
    private static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    public static ServerWorldDatabase instance = new ServerWorldDatabase();
    public String CommandLineAdminUsername = "admin";
    public String CommandLineAdminPassword;
    public boolean doAdmin = true;
    public DBSchema dbSchema = null;
    static CharsetEncoder asciiEncoder = Charset.forName("US-ASCII").newEncoder();
    Connection conn;
    private static final String nullChar = String.valueOf('\u0000');

    public DBSchema getDBSchema() {
        if (this.dbSchema == null) {
            this.dbSchema = new DBSchema(this.conn);
        }

        return this.dbSchema;
    }

    public void executeQuery(String string, KahluaTable kahluaTable) throws SQLException {
        PreparedStatement preparedStatement = this.conn.prepareStatement(string);
        KahluaTableIterator kahluaTableIterator = kahluaTable.iterator();
        int _int = 1;

        while (kahluaTableIterator.advance()) {
            preparedStatement.setString(_int++, (String)kahluaTableIterator.getValue());
        }

        preparedStatement.executeUpdate();
    }

    public ArrayList<DBResult> getTableResult(String table) throws SQLException {
        ArrayList arrayList0 = new ArrayList();
        String string0 = "SELECT * FROM " + table;
        if ("userlog".equals(table)) {
            string0 = string0 + " ORDER BY lastUpdate DESC";
        }

        PreparedStatement preparedStatement = this.conn.prepareStatement(string0);
        ResultSet resultSet0 = preparedStatement.executeQuery();
        DatabaseMetaData databaseMetaData = this.conn.getMetaData();
        ResultSet resultSet1 = databaseMetaData.getColumns(null, null, table, null);
        ArrayList arrayList1 = new ArrayList();
        DBResult dBResult = new DBResult();

        while (resultSet1.next()) {
            String string1 = resultSet1.getString(4);
            if (!string1.equals("world")
                && !string1.equals("moderator")
                && !string1.equals("admin")
                && !string1.equals("password")
                && !string1.equals("encryptedPwd")
                && !string1.equals("pwdEncryptType")
                && !string1.equals("transactionID")) {
                arrayList1.add(string1);
            }
        }

        dBResult.setColumns(arrayList1);
        dBResult.setTableName(table);

        while (resultSet0.next()) {
            for (int _int = 0; _int < arrayList1.size(); _int++) {
                String string2 = (String)arrayList1.get(_int);
                String string3 = resultSet0.getString(string2);
                if ("'false'".equals(string3)) {
                    string3 = "false";
                }

                if ("'true'".equals(string3)) {
                    string3 = "true";
                }

                if (string3 == null) {
                    string3 = "";
                }

                dBResult.getValues().put(string2, string3);
            }

            arrayList0.add(dBResult);
            dBResult = new DBResult();
            dBResult.setColumns(arrayList1);
            dBResult.setTableName(table);
        }

        preparedStatement.close();
        return arrayList0;
    }

    public void saveAllTransactionsID(HashMap<String, Integer> map) {
        try {
            Iterator iterator = map.keySet().iterator();
            PreparedStatement preparedStatement = null;

            while (iterator.hasNext()) {
                String string = (String)iterator.next();
                Integer integer = (Integer)map.get(string);
                preparedStatement = this.conn.prepareStatement("UPDATE whitelist SET transactionID = ? WHERE username = ?");
                preparedStatement.setString(1, integer.toString());
                preparedStatement.setString(2, string);
                preparedStatement.executeUpdate();
                preparedStatement.close();
            }
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    public void saveTransactionID(String username, Integer transactionID) {
        try {
            if (!this.containsUser(username)) {
                this.addUser(username, "");
            }

            PreparedStatement preparedStatement = this.conn.prepareStatement("UPDATE whitelist SET transactionID = ? WHERE username = ?");
            preparedStatement.setString(1, transactionID.toString());
            preparedStatement.setString(2, username);
            preparedStatement.executeUpdate();
            preparedStatement.close();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    public boolean containsUser(String user) {
        try {
            PreparedStatement preparedStatement = this.conn.prepareStatement("SELECT * FROM whitelist WHERE username = ? AND world = ?");
            preparedStatement.setString(1, user);
            preparedStatement.setString(2, Core.GameSaveWorld);
            ResultSet resultSet = preparedStatement.executeQuery();
            if (resultSet.next()) {
                preparedStatement.close();
                return true;
            }

            preparedStatement.close();
        } catch (SQLException sQLException) {
            sQLException.printStackTrace();
        }

        return false;
    }

    public boolean containsCaseinsensitiveUser(String user) {
        try {
            PreparedStatement preparedStatement = this.conn.prepareStatement("SELECT * FROM whitelist WHERE LOWER(username) = LOWER(?) AND world = ?");
            preparedStatement.setString(1, user);
            preparedStatement.setString(2, Core.GameSaveWorld);
            ResultSet resultSet = preparedStatement.executeQuery();
            if (resultSet.next()) {
                preparedStatement.close();
                return true;
            }

            preparedStatement.close();
        } catch (SQLException sQLException) {
            sQLException.printStackTrace();
        }

        return false;
    }

    public String changeUsername(String user, String newUsername) throws SQLException {
        PreparedStatement preparedStatement = this.conn.prepareStatement("SELECT * FROM whitelist WHERE username = ? AND world = ?");
        preparedStatement.setString(1, user);
        preparedStatement.setString(2, Core.GameSaveWorld);
        ResultSet resultSet = preparedStatement.executeQuery();
        if (resultSet.next()) {
            String string = resultSet.getString("id");
            preparedStatement.close();
            preparedStatement = this.conn.prepareStatement("UPDATE whitelist SET username = ? WHERE id = ?");
            preparedStatement.setString(1, newUsername);
            preparedStatement.setString(2, string);
            preparedStatement.executeUpdate();
            preparedStatement.close();
            return "Changed " + user + " user's name into " + newUsername;
        } else {
            return !ServerOptions.instance.getBoolean("Open")
                ? "User \"" + user + "\" is not in the whitelist, use /adduser first"
                : "Changed's name " + user + " into " + newUsername;
        }
    }

    public String addUser(String user, String pass) throws SQLException {
        if (this.containsCaseinsensitiveUser(user)) {
            return "A user with this name already exists";
        } else {
            try {
                PreparedStatement preparedStatement = this.conn.prepareStatement("SELECT * FROM whitelist WHERE username = ? AND world = ?");
                preparedStatement.setString(1, user);
                preparedStatement.setString(2, Core.GameSaveWorld);
                ResultSet resultSet = preparedStatement.executeQuery();
                if (resultSet.next()) {
                    preparedStatement.close();
                    return "User " + user + " already exist.";
                }

                preparedStatement.close();
                preparedStatement = this.conn
                    .prepareStatement("INSERT INTO whitelist (world, username, password, encryptedPwd, pwdEncryptType) VALUES (?, ?, ?, 'true', '2')");
                preparedStatement.setString(1, Core.GameSaveWorld);
                preparedStatement.setString(2, user);
                preparedStatement.setString(3, pass);
                preparedStatement.executeUpdate();
                preparedStatement.close();
            } catch (SQLException sQLException) {
                sQLException.printStackTrace();
            }

            return "User " + user + " created with the password " + pass;
        }
    }

    public void updateDisplayName(String user, String displayName) {
        try {
            PreparedStatement preparedStatement = this.conn.prepareStatement("SELECT * FROM whitelist WHERE username = ? AND world = ?");
            preparedStatement.setString(1, user);
            preparedStatement.setString(2, Core.GameSaveWorld);
            ResultSet resultSet = preparedStatement.executeQuery();
            if (resultSet.next()) {
                preparedStatement.close();
                preparedStatement = this.conn.prepareStatement("UPDATE whitelist SET displayName = ? WHERE username = ?");
                preparedStatement.setString(1, displayName);
                preparedStatement.setString(2, user);
                preparedStatement.executeUpdate();
                preparedStatement.close();
            }

            preparedStatement.close();
        } catch (SQLException sQLException) {
            sQLException.printStackTrace();
        }
    }

    public String getDisplayName(String username) {
        try {
            PreparedStatement preparedStatement = this.conn.prepareStatement("SELECT * FROM whitelist WHERE username = ? AND world = ?");
            preparedStatement.setString(1, username);
            preparedStatement.setString(2, Core.GameSaveWorld);
            ResultSet resultSet = preparedStatement.executeQuery();
            if (resultSet.next()) {
                String string = resultSet.getString("displayName");
                preparedStatement.close();
                return string;
            }

            preparedStatement.close();
        } catch (SQLException sQLException) {
            sQLException.printStackTrace();
        }

        return null;
    }

    public String removeUser(String username) throws SQLException {
        try {
            PreparedStatement preparedStatement = this.conn.prepareStatement("DELETE FROM whitelist WHERE world = ? and username = ?");
            preparedStatement.setString(1, Core.GameSaveWorld);
            preparedStatement.setString(2, username);
            preparedStatement.executeUpdate();
            preparedStatement.close();
        } catch (SQLException sQLException) {
            sQLException.printStackTrace();
        }

        return "User " + username + " removed from white list";
    }

    public void removeUserLog(String username, String type, String text) throws SQLException {
        try {
            PreparedStatement preparedStatement = this.conn.prepareStatement("DELETE FROM userlog WHERE username = ? AND type = ? AND text = ?");
            preparedStatement.setString(1, username);
            preparedStatement.setString(2, type);
            preparedStatement.setString(3, text);
            preparedStatement.executeUpdate();
            preparedStatement.close();
        } catch (SQLException sQLException) {
            sQLException.printStackTrace();
        }
    }

    public void create() throws SQLException, ClassNotFoundException {
        File file0 = new File(zombie.ZomboidFileSystem.instance.getCacheDir() + File.separator + "db");
        if (!file0.exists()) {
            file0.mkdirs();
        }

        File file1 = new File(zombie.ZomboidFileSystem.instance.getCacheDir() + File.separator + "db" + File.separator + GameServer.ServerName + ".db");
        file1.setReadable(true, false);
        file1.setExecutable(true, false);
        file1.setWritable(true, false);
        DebugLog.log("user database \"" + file1.getPath() + "\"");
        if (!file1.exists()) {
            try {
                file1.createNewFile();
                this.conn = PZSQLUtils.getConnection(file1.getAbsolutePath());
                Statement statement0 = this.conn.createStatement();
                statement0.executeUpdate(
                    "CREATE TABLE [whitelist] ([id] INTEGER  PRIMARY KEY AUTOINCREMENT NOT NULL,[world] TEXT DEFAULT '"
                        + GameServer.ServerName
                        + "' NULL,[username] TEXT  NULL,[password] TEXT  NULL, [admin] BOOLEAN DEFAULT false NULL, [moderator] BOOLEAN DEFAULT false NULL, [banned] BOOLEAN DEFAULT false NULL, [priority] BOOLEAN DEFAULT false NULL,  [lastConnection] TEXT NULL)"
                );
                statement0.executeUpdate("CREATE UNIQUE INDEX [id] ON [whitelist]([id]  ASC)");
                statement0.executeUpdate("CREATE UNIQUE INDEX [username] ON [whitelist]([username]  ASC)");
                statement0.executeUpdate("CREATE TABLE [bannedip] ([ip] TEXT NOT NULL,[username] TEXT NULL, [reason] TEXT NULL)");
                statement0.close();
            } catch (Exception exception0) {
                exception0.printStackTrace();
                DebugLog.log("failed to create user database, server shut down");
                System.exit(1);
            }
        }

        if (this.conn == null) {
            try {
                this.conn = PZSQLUtils.getConnection(file1.getAbsolutePath());
            } catch (Exception exception1) {
                exception1.printStackTrace();
                DebugLog.log("failed to open user database, server shut down");
                System.exit(1);
            }
        }

        DatabaseMetaData databaseMetaData = this.conn.getMetaData();
        ResultSet resultSet0 = databaseMetaData.getColumns(null, null, "whitelist", "admin");
        Statement statement1 = this.conn.createStatement();
        if (!resultSet0.next()) {
            statement1.executeUpdate("ALTER TABLE 'whitelist' ADD 'admin' BOOLEAN NULL DEFAULT false");
        }

        resultSet0.close();
        resultSet0 = databaseMetaData.getColumns(null, null, "whitelist", "moderator");
        if (!resultSet0.next()) {
            statement1.executeUpdate("ALTER TABLE 'whitelist' ADD 'moderator' BOOLEAN NULL DEFAULT false");
        }

        resultSet0.close();
        resultSet0 = databaseMetaData.getColumns(null, null, "whitelist", "banned");
        if (!resultSet0.next()) {
            statement1.executeUpdate("ALTER TABLE 'whitelist' ADD 'banned' BOOLEAN NULL DEFAULT false");
        }

        resultSet0.close();
        resultSet0 = databaseMetaData.getColumns(null, null, "whitelist", "priority");
        if (!resultSet0.next()) {
            statement1.executeUpdate("ALTER TABLE 'whitelist' ADD 'priority' BOOLEAN NULL DEFAULT false");
        }

        resultSet0.close();
        resultSet0 = databaseMetaData.getColumns(null, null, "whitelist", "lastConnection");
        if (!resultSet0.next()) {
            statement1.executeUpdate("ALTER TABLE 'whitelist' ADD 'lastConnection' TEXT NULL");
        }

        resultSet0.close();
        resultSet0 = databaseMetaData.getColumns(null, null, "whitelist", "encryptedPwd");
        if (!resultSet0.next()) {
            statement1.executeUpdate("ALTER TABLE 'whitelist' ADD 'encryptedPwd' BOOLEAN NULL DEFAULT false");
        }

        resultSet0.close();
        resultSet0 = databaseMetaData.getColumns(null, null, "whitelist", "pwdEncryptType");
        if (!resultSet0.next()) {
            statement1.executeUpdate("ALTER TABLE 'whitelist' ADD 'pwdEncryptType' INTEGER NULL DEFAULT 1");
        }

        resultSet0.close();
        if (SteamUtils.isSteamModeEnabled()) {
            resultSet0 = databaseMetaData.getColumns(null, null, "whitelist", "steamid");
            if (!resultSet0.next()) {
                statement1.executeUpdate("ALTER TABLE 'whitelist' ADD 'steamid' TEXT NULL");
            }

            resultSet0.close();
            resultSet0 = databaseMetaData.getColumns(null, null, "whitelist", "ownerid");
            if (!resultSet0.next()) {
                statement1.executeUpdate("ALTER TABLE 'whitelist' ADD 'ownerid' TEXT NULL");
            }

            resultSet0.close();
        }

        resultSet0 = databaseMetaData.getColumns(null, null, "whitelist", "accesslevel");
        if (!resultSet0.next()) {
            statement1.executeUpdate("ALTER TABLE 'whitelist' ADD 'accesslevel' TEXT NULL");
        }

        resultSet0.close();
        resultSet0 = databaseMetaData.getColumns(null, null, "whitelist", "transactionID");
        if (!resultSet0.next()) {
            statement1.executeUpdate("ALTER TABLE 'whitelist' ADD 'transactionID' INTEGER NULL");
        }

        resultSet0.close();
        resultSet0 = databaseMetaData.getColumns(null, null, "whitelist", "displayName");
        if (!resultSet0.next()) {
            statement1.executeUpdate("ALTER TABLE 'whitelist' ADD 'displayName' TEXT NULL");
        }

        resultSet0.close();
        resultSet0 = statement1.executeQuery("SELECT * FROM sqlite_master WHERE type = 'index' AND sql LIKE '%UNIQUE%' and name = 'username'");
        if (!resultSet0.next()) {
            try {
                statement1.executeUpdate("CREATE UNIQUE INDEX [username] ON [whitelist]([username]  ASC)");
            } catch (Exception exception2) {
                System.out
                    .println("Can't create the username index because some of the username in the database are in double, will drop the double username.");
                statement1.executeUpdate(
                    "DELETE FROM whitelist WHERE whitelist.rowid > (SELECT rowid FROM whitelist dbl WHERE whitelist.rowid <> dbl.rowid AND  whitelist.username = dbl.username);"
                );
                statement1.executeUpdate("CREATE UNIQUE INDEX [username] ON [whitelist]([username]  ASC)");
            }
        }

        resultSet0 = databaseMetaData.getTables(null, null, "bannedip", null);
        if (!resultSet0.next()) {
            statement1.executeUpdate("CREATE TABLE [bannedip] ([ip] TEXT NOT NULL,[username] TEXT NULL, [reason] TEXT NULL)");
        }

        resultSet0.close();
        resultSet0 = databaseMetaData.getTables(null, null, "bannedid", null);
        if (!resultSet0.next()) {
            statement1.executeUpdate("CREATE TABLE [bannedid] ([steamid] TEXT NOT NULL, [reason] TEXT NULL)");
        }

        resultSet0.close();
        resultSet0 = databaseMetaData.getTables(null, null, "userlog", null);
        if (!resultSet0.next()) {
            statement1.executeUpdate(
                "CREATE TABLE [userlog] ([id] INTEGER  PRIMARY KEY AUTOINCREMENT NOT NULL,[username] TEXT  NULL,[type] TEXT  NULL, [text] TEXT  NULL, [issuedBy] TEXT  NULL, [amount] INTEGER NULL, [lastUpdate] TEXT NULL)"
            );
        }

        resultSet0.close();
        resultSet0 = databaseMetaData.getColumns(null, null, "userlog", "lastUpdate");
        if (!resultSet0.next()) {
            statement1.executeUpdate("ALTER TABLE 'userlog' ADD 'lastUpdate' TEXT NULL");
        }

        resultSet0.close();
        resultSet0 = databaseMetaData.getColumns(null, null, "whitelist", "moderator");
        if (resultSet0.next()) {
        }

        resultSet0.close();
        resultSet0 = databaseMetaData.getColumns(null, null, "whitelist", "admin");
        if (resultSet0.next()) {
            resultSet0.close();
            PreparedStatement preparedStatement0 = this.conn.prepareStatement("SELECT * FROM whitelist where admin = 'true'");
            ResultSet resultSet1 = preparedStatement0.executeQuery();

            while (resultSet1.next()) {
                PreparedStatement preparedStatement1 = this.conn.prepareStatement("UPDATE whitelist set accesslevel = 'admin' where id = ?");
                preparedStatement1.setString(1, resultSet1.getString("id"));
                System.out.println(resultSet1.getString("username"));
                preparedStatement1.executeUpdate();
            }
        }

        resultSet0 = databaseMetaData.getTables(null, null, "tickets", null);
        if (!resultSet0.next()) {
            statement1.executeUpdate(
                "CREATE TABLE [tickets] ([id] INTEGER  PRIMARY KEY AUTOINCREMENT NOT NULL, [message] TEXT NOT NULL, [author] TEXT NOT NULL,[answeredID] INTEGER,[viewed] BOOLEAN NULL DEFAULT false)"
            );
        }

        resultSet0.close();
        PreparedStatement preparedStatement2 = this.conn.prepareStatement("SELECT * FROM whitelist WHERE username = ?");
        preparedStatement2.setString(1, this.CommandLineAdminUsername);
        resultSet0 = preparedStatement2.executeQuery();
        if (!resultSet0.next()) {
            preparedStatement2.close();
            String string0 = this.CommandLineAdminPassword;
            if (string0 == null || string0.isEmpty()) {
                Scanner scanner = new Scanner(new InputStreamReader(System.in));
                System.out.println("User 'admin' not found, creating it ");
                System.out.println("Command line admin password: " + this.CommandLineAdminPassword);
                System.out.println("Enter new administrator password: ");

                for (string0 = scanner.nextLine(); string0 == null || "".equals(string0); string0 = scanner.nextLine()) {
                    System.out.println("Enter new administrator password: ");
                }

                System.out.println("Confirm the password: ");

                for (String string1 = scanner.nextLine(); string1 == null || "".equals(string1) || !string0.equals(string1); string1 = scanner.nextLine()) {
                    System.out.println("Wrong password, confirm the password: ");
                }
            }

            if (this.doAdmin) {
                preparedStatement2 = this.conn
                    .prepareStatement(
                        "INSERT INTO whitelist (username, password, accesslevel, encryptedPwd, pwdEncryptType) VALUES (?, ?, 'admin', 'true', '2')"
                    );
            } else {
                preparedStatement2 = this.conn
                    .prepareStatement("INSERT INTO whitelist (username, password, encryptedPwd, pwdEncryptType) VALUES (?, ?, 'true', '2')");
            }

            preparedStatement2.setString(1, this.CommandLineAdminUsername);
            preparedStatement2.setString(2, PZcrypt.hash(encrypt(string0)));
            preparedStatement2.executeUpdate();
            preparedStatement2.close();
            System.out.println("Administrator account '" + this.CommandLineAdminUsername + "' created.");
        } else {
            preparedStatement2.close();
        }

        statement1.close();
        if (this.CommandLineAdminPassword != null && !this.CommandLineAdminPassword.isEmpty()) {
            String string2 = PZcrypt.hash(encrypt(this.CommandLineAdminPassword));
            PreparedStatement preparedStatement3 = this.conn.prepareStatement("SELECT * FROM whitelist WHERE username = ?");
            preparedStatement3.setString(1, this.CommandLineAdminUsername);
            resultSet0 = preparedStatement3.executeQuery();
            if (resultSet0.next()) {
                preparedStatement3.close();
                preparedStatement3 = this.conn.prepareStatement("UPDATE whitelist SET password = ? WHERE username = ?");
                preparedStatement3.setString(1, string2);
                preparedStatement3.setString(2, this.CommandLineAdminUsername);
                preparedStatement3.executeUpdate();
                System.out.println("admin password changed via -adminpassword option");
            } else {
                System.out.println("ERROR: -adminpassword ignored, no '" + this.CommandLineAdminUsername + "' account in db");
            }

            preparedStatement3.close();
        }
    }

    public void close() {
        try {
            if (this.conn != null) {
                this.conn.close();
            }
        } catch (SQLException sQLException) {
            sQLException.printStackTrace();
        }
    }

    public static boolean isValidUserName(String user) {
        if (user == null
            || user.trim().isEmpty()
            || user.contains(";")
            || user.contains("@")
            || user.contains("$")
            || user.contains(",")
            || user.contains("/")
            || user.contains(".")
            || user.contains("'")
            || user.contains("?")
            || user.contains("\"")
            || user.trim().length() < 3
            || user.length() > 20) {
            return false;
        } else if (user.contains(nullChar)) {
            return false;
        } else {
            return user.trim().equals("admin") ? true : !user.trim().toLowerCase().startsWith("admin");
        }
    }

    public ServerWorldDatabase.LogonResult authClient(String user, String pass, String ip, long steamID) {
        System.out.println("User " + user + " is trying to connect.");
        ServerWorldDatabase.LogonResult logonResult = new ServerWorldDatabase.LogonResult();
        if (!ServerOptions.instance.AllowNonAsciiUsername.getValue() && !asciiEncoder.canEncode(user)) {
            logonResult.bAuthorized = false;
            logonResult.dcReason = "NonAsciiCharacters";
            return logonResult;
        } else if (!isValidUserName(user)) {
            logonResult.bAuthorized = false;
            logonResult.dcReason = "InvalidUsername";
            return logonResult;
        } else {
            try {
                if (!SteamUtils.isSteamModeEnabled() && !ip.equals("127.0.0.1")) {
                    PreparedStatement preparedStatement0 = this.conn.prepareStatement("SELECT * FROM bannedip WHERE ip = ?");
                    preparedStatement0.setString(1, ip);
                    ResultSet resultSet0 = preparedStatement0.executeQuery();
                    if (resultSet0.next()) {
                        logonResult.bAuthorized = false;
                        logonResult.bannedReason = resultSet0.getString("reason");
                        logonResult.banned = true;
                        preparedStatement0.close();
                        return logonResult;
                    }

                    preparedStatement0.close();
                }

                if (isNullOrEmpty(pass) && ServerOptions.instance.Open.getValue() && ServerOptions.instance.AutoCreateUserInWhiteList.getValue()) {
                    logonResult.dcReason = "UserPasswordRequired";
                    logonResult.bAuthorized = false;
                    return logonResult;
                }

                PreparedStatement preparedStatement1 = this.conn.prepareStatement("SELECT * FROM whitelist WHERE LOWER(username) = LOWER(?) AND world = ?");
                preparedStatement1.setString(1, user);
                preparedStatement1.setString(2, Core.GameSaveWorld);
                ResultSet resultSet1 = preparedStatement1.executeQuery();
                if (resultSet1.next()) {
                    if (!isNullOrEmpty(resultSet1.getString("password"))
                        && (resultSet1.getString("encryptedPwd").equals("false") || resultSet1.getString("encryptedPwd").equals("N"))) {
                        String string0 = resultSet1.getString("password");
                        String string1 = encrypt(string0);
                        PreparedStatement preparedStatement2 = this.conn
                            .prepareStatement("UPDATE whitelist SET encryptedPwd = 'true' WHERE username = ? and password = ?");
                        preparedStatement2.setString(1, user);
                        preparedStatement2.setString(2, string0);
                        preparedStatement2.executeUpdate();
                        preparedStatement2.close();
                        preparedStatement2 = this.conn.prepareStatement("UPDATE whitelist SET password = ? WHERE username = ? AND password = ?");
                        preparedStatement2.setString(1, string1);
                        preparedStatement2.setString(2, user);
                        preparedStatement2.setString(3, string0);
                        preparedStatement2.executeUpdate();
                        preparedStatement2.close();
                        resultSet1 = preparedStatement1.executeQuery();
                    }

                    if (!isNullOrEmpty(resultSet1.getString("password")) && resultSet1.getInt("pwdEncryptType") == 1) {
                        String string2 = resultSet1.getString("password");
                        String string3 = PZcrypt.hash(string2);
                        PreparedStatement preparedStatement3 = this.conn
                            .prepareStatement("UPDATE whitelist SET pwdEncryptType = '2', password = ? WHERE username = ? AND password = ?");
                        preparedStatement3.setString(1, string3);
                        preparedStatement3.setString(2, user);
                        preparedStatement3.setString(3, string2);
                        preparedStatement3.executeUpdate();
                        preparedStatement3.close();
                        resultSet1 = preparedStatement1.executeQuery();
                    }

                    if (!isNullOrEmpty(resultSet1.getString("password")) && !resultSet1.getString("password").equals(pass)) {
                        logonResult.bAuthorized = false;
                        preparedStatement1.close();
                        if (isNullOrEmpty(pass)) {
                            logonResult.dcReason = "DuplicateAccount";
                        } else {
                            logonResult.dcReason = "InvalidUsernamePassword";
                        }

                        return logonResult;
                    }

                    logonResult.bAuthorized = true;
                    logonResult.admin = "true".equals(resultSet1.getString("admin")) || "Y".equals(resultSet1.getString("admin"));
                    logonResult.accessLevel = resultSet1.getString("accesslevel");
                    if (logonResult.accessLevel == null) {
                        logonResult.accessLevel = "";
                        if (logonResult.admin) {
                            logonResult.accessLevel = "admin";
                        }

                        this.setAccessLevel(user, logonResult.accessLevel);
                    }

                    logonResult.banned = "true".equals(resultSet1.getString("banned")) || "Y".equals(resultSet1.getString("banned"));
                    if (logonResult.banned) {
                        logonResult.bAuthorized = false;
                    }

                    if (resultSet1.getString("transactionID") == null) {
                        logonResult.transactionID = 0;
                    } else {
                        logonResult.transactionID = Integer.parseInt(resultSet1.getString("transactionID"));
                    }

                    logonResult.priority = resultSet1.getString("priority").equals("true");
                    preparedStatement1.close();
                    return logonResult;
                }

                if (ServerOptions.instance.Open.getValue()) {
                    if (!this.isNewAccountAllowed(ip, steamID)) {
                        preparedStatement1.close();
                        logonResult.bAuthorized = false;
                        logonResult.dcReason = "MaxAccountsReached";
                        return logonResult;
                    }

                    logonResult.bAuthorized = true;
                    logonResult.newUser = true;
                    preparedStatement1.close();
                    return logonResult;
                }

                logonResult.bAuthorized = false;
                logonResult.dcReason = "UnknownUsername";
                preparedStatement1.close();
            } catch (Exception exception) {
                exception.printStackTrace();
            }

            return logonResult;
        }
    }

    public ServerWorldDatabase.LogonResult authClient(long steamID) {
        String string = SteamUtils.convertSteamIDToString(steamID);
        System.out.println("Steam client " + string + " is initiating a connection.");
        ServerWorldDatabase.LogonResult logonResult = new ServerWorldDatabase.LogonResult();

        try {
            PreparedStatement preparedStatement = this.conn.prepareStatement("SELECT * FROM bannedid WHERE steamid = ?");
            preparedStatement.setString(1, string);
            ResultSet resultSet = preparedStatement.executeQuery();
            if (resultSet.next()) {
                logonResult.bAuthorized = false;
                logonResult.bannedReason = resultSet.getString("reason");
                logonResult.banned = true;
                preparedStatement.close();
                return logonResult;
            }

            preparedStatement.close();
            logonResult.bAuthorized = true;
        } catch (Exception exception) {
            exception.printStackTrace();
        }

        return logonResult;
    }

    public ServerWorldDatabase.LogonResult authOwner(long steamID, long ownerID) {
        String string0 = SteamUtils.convertSteamIDToString(steamID);
        String string1 = SteamUtils.convertSteamIDToString(ownerID);
        System.out.println("Steam client " + string0 + " borrowed the game from " + string1);
        ServerWorldDatabase.LogonResult logonResult = new ServerWorldDatabase.LogonResult();

        try {
            PreparedStatement preparedStatement = this.conn.prepareStatement("SELECT * FROM bannedid WHERE steamid = ?");
            preparedStatement.setString(1, string1);
            ResultSet resultSet = preparedStatement.executeQuery();
            if (resultSet.next()) {
                logonResult.bAuthorized = false;
                logonResult.bannedReason = resultSet.getString("reason");
                logonResult.banned = true;
                preparedStatement.close();
                return logonResult;
            }

            preparedStatement.close();
            logonResult.bAuthorized = true;
            preparedStatement = this.conn.prepareStatement("UPDATE whitelist SET ownerid = ? where steamid = ?");
            preparedStatement.setString(1, string1);
            preparedStatement.setString(2, string0);
            preparedStatement.executeUpdate();
            preparedStatement.close();
        } catch (Exception exception) {
            exception.printStackTrace();
        }

        return logonResult;
    }

    private boolean isNewAccountAllowed(String var1, long _long) {
        int int0 = ServerOptions.instance.MaxAccountsPerUser.getValue();
        if (int0 <= 0) {
            return true;
        } else if (!SteamUtils.isSteamModeEnabled()) {
            return true;
        } else {
            String string = SteamUtils.convertSteamIDToString(_long);
            int int1 = 0;

            try {
                PreparedStatement preparedStatement = this.conn
                    .prepareStatement("SELECT * FROM whitelist WHERE steamid = ? AND ((accessLevel = ?) OR (accessLevel is NULL))");

                try {
                    preparedStatement.setString(1, string);
                    preparedStatement.setString(2, "");
                    ResultSet resultSet = preparedStatement.executeQuery();

                    while (resultSet.next()) {
                        int1++;
                    }
                } catch (Throwable throwable0) {
                    if (preparedStatement != null) {
                        try {
                            preparedStatement.close();
                        } catch (Throwable throwable1) {
                            throwable0.addSuppressed(throwable1);
                        }
                    }

                    throw throwable0;
                }

                if (preparedStatement != null) {
                    preparedStatement.close();
                }
            } catch (Exception exception) {
                DebugLog.Multiplayer.printException(exception, "Query execution failed", LogSeverity.Error);
                return true;
            }

            DebugLog.Multiplayer.debugln("IsNewAccountAllowed: steam-id=%d count=%d/%d", _long, int1, int0);
            return int1 < int0;
        }
    }

    public static String encrypt(String previousPwd) {
        if (isNullOrEmpty(previousPwd)) {
            return "";
        } else {
            byte[] _byte = null;

            try {
                _byte = MessageDigest.getInstance("MD5").digest(previousPwd.getBytes());
            } catch (NoSuchAlgorithmException noSuchAlgorithmException) {
                System.out.println("Can't encrypt password");
                noSuchAlgorithmException.printStackTrace();
            }

            StringBuilder stringBuilder = new StringBuilder();

            for (int _int = 0; _int < _byte.length; _int++) {
                String string = Integer.toHexString(_byte[_int]);
                if (string.length() == 1) {
                    stringBuilder.append('0');
                    stringBuilder.append(string.charAt(string.length() - 1));
                } else {
                    stringBuilder.append(string.substring(string.length() - 2));
                }
            }

            return stringBuilder.toString();
        }
    }

    public String changePwd(String username, String previousPwd, String newPwd) throws SQLException {
        PreparedStatement preparedStatement = this.conn.prepareStatement("SELECT * FROM whitelist WHERE username = ? AND password = ? AND world = ?");
        preparedStatement.setString(1, username);
        preparedStatement.setString(2, previousPwd);
        preparedStatement.setString(3, Core.GameSaveWorld);
        ResultSet resultSet = preparedStatement.executeQuery();
        if (resultSet.next()) {
            preparedStatement.close();
            preparedStatement = this.conn.prepareStatement("UPDATE whitelist SET pwdEncryptType = '2', password = ? WHERE username = ? and password = ?");
            preparedStatement.setString(1, newPwd);
            preparedStatement.setString(2, username);
            preparedStatement.setString(3, previousPwd);
            preparedStatement.executeUpdate();
            preparedStatement.close();
            return "Your new password is " + newPwd;
        } else {
            preparedStatement.close();
            return "Wrong password for user " + username;
        }
    }

    public String grantAdmin(String username, boolean setAdmin) throws SQLException {
        PreparedStatement preparedStatement = this.conn.prepareStatement("SELECT * FROM whitelist WHERE username = ? AND world = ?");
        preparedStatement.setString(1, username);
        preparedStatement.setString(2, Core.GameSaveWorld);
        ResultSet resultSet = preparedStatement.executeQuery();
        if (resultSet.next()) {
            preparedStatement.close();
            preparedStatement = this.conn.prepareStatement("UPDATE whitelist SET admin = ? WHERE username = ?");
            preparedStatement.setString(1, setAdmin ? "true" : "false");
            preparedStatement.setString(2, username);
            preparedStatement.executeUpdate();
            preparedStatement.close();
            return setAdmin ? "User " + username + " is now admin" : "User " + username + " is no longer admin";
        } else {
            preparedStatement.close();
            return "User \"" + username + "\" is not in the whitelist, use /adduser first";
        }
    }

    public String setAccessLevel(String username, String accessLevel) throws SQLException {
        accessLevel = accessLevel.trim();
        if (!this.containsUser(username)) {
            this.addUser(username, "");
        }

        PreparedStatement preparedStatement = this.conn.prepareStatement("SELECT * FROM whitelist WHERE username = ? AND world = ?");
        preparedStatement.setString(1, username);
        preparedStatement.setString(2, Core.GameSaveWorld);
        ResultSet resultSet = preparedStatement.executeQuery();
        if (resultSet.next()) {
            preparedStatement.close();
            preparedStatement = this.conn.prepareStatement("UPDATE whitelist SET accesslevel = ? WHERE username = ?");
            preparedStatement.setString(1, accessLevel);
            preparedStatement.setString(2, username);
            preparedStatement.executeUpdate();
            preparedStatement.close();
            return accessLevel.equals("") ? "User " + username + " no longer has access level" : "User " + username + " is now " + accessLevel;
        } else {
            preparedStatement.close();
            return "User \"" + username + "\" is not in the whitelist, use /adduser first";
        }
    }

    public ArrayList<Userlog> getUserlog(String username) {
        ArrayList arrayList = new ArrayList();

        try {
            PreparedStatement preparedStatement = this.conn.prepareStatement("SELECT * FROM userlog WHERE username = ?");
            preparedStatement.setString(1, username);
            ResultSet resultSet = preparedStatement.executeQuery();

            while (resultSet.next()) {
                arrayList.add(
                    new Userlog(
                        username,
                        resultSet.getString("type"),
                        resultSet.getString("text"),
                        resultSet.getString("issuedBy"),
                        resultSet.getInt("amount"),
                        resultSet.getString("lastUpdate")
                    )
                );
            }

            preparedStatement.close();
        } catch (SQLException sQLException) {
            sQLException.printStackTrace();
        }

        return arrayList;
    }

    public void addUserlog(String username, Userlog.UserlogType type, String text, String issuedBy, int amount) {
        try {
            boolean _boolean = true;
            String string = dateFormat.format(Calendar.getInstance().getTime());
            if (type != Userlog.UserlogType.LuaChecksum && type != Userlog.UserlogType.DupeItem) {
                if (type == Userlog.UserlogType.Kicked
                    || type == Userlog.UserlogType.Banned
                    || type == Userlog.UserlogType.SuspiciousActivity
                    || type == Userlog.UserlogType.UnauthorizedPacket) {
                    PreparedStatement preparedStatement0 = this.conn
                        .prepareStatement("SELECT * FROM userlog WHERE username = ? AND type = ? AND text = ? AND issuedBy = ?");
                    preparedStatement0.setString(1, username);
                    preparedStatement0.setString(2, type.toString());
                    preparedStatement0.setString(3, text);
                    preparedStatement0.setString(4, issuedBy);
                    ResultSet resultSet0 = preparedStatement0.executeQuery();
                    if (resultSet0.next()) {
                        _boolean = false;
                        amount = Integer.parseInt(resultSet0.getString("amount")) + 1;
                        preparedStatement0.close();
                        PreparedStatement preparedStatement1 = this.conn
                            .prepareStatement("UPDATE userlog set amount = ?, lastUpdate = ? WHERE username = ? AND type = ? AND text = ? AND issuedBy = ?");
                        preparedStatement1.setString(1, String.valueOf(amount));
                        preparedStatement1.setString(2, string);
                        preparedStatement1.setString(3, username);
                        preparedStatement1.setString(4, type.toString());
                        preparedStatement1.setString(5, text);
                        preparedStatement1.setString(6, issuedBy);
                        preparedStatement1.executeUpdate();
                        preparedStatement1.close();
                    }
                }
            } else {
                PreparedStatement preparedStatement2 = this.conn.prepareStatement("SELECT * FROM userlog WHERE username = ? AND type = ?");
                preparedStatement2.setString(1, username);
                preparedStatement2.setString(2, type.toString());
                ResultSet resultSet1 = preparedStatement2.executeQuery();
                if (resultSet1.next()) {
                    _boolean = false;
                    amount = Integer.parseInt(resultSet1.getString("amount")) + 1;
                    preparedStatement2.close();
                    PreparedStatement preparedStatement3 = this.conn
                        .prepareStatement("UPDATE userlog set amount = ?, lastUpdate = ?, text = ? WHERE username = ? AND type = ?");
                    preparedStatement3.setString(1, String.valueOf(amount));
                    preparedStatement3.setString(2, string);
                    preparedStatement3.setString(3, text);
                    preparedStatement3.setString(4, username);
                    preparedStatement3.setString(5, type.toString());
                    preparedStatement3.executeUpdate();
                    preparedStatement3.close();
                }
            }

            if (_boolean) {
                PreparedStatement preparedStatement4 = this.conn
                    .prepareStatement("INSERT INTO userlog (username, type, text, issuedBy, amount, lastUpdate) VALUES (?, ?, ?, ?, ?, ?)");
                preparedStatement4.setString(1, username);
                preparedStatement4.setString(2, type.toString());
                preparedStatement4.setString(3, text);
                preparedStatement4.setString(4, issuedBy);
                preparedStatement4.setString(5, String.valueOf(amount));
                preparedStatement4.setString(6, string);
                preparedStatement4.executeUpdate();
                preparedStatement4.close();
            }
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    public String banUser(String username, boolean ban) throws SQLException {
        PreparedStatement preparedStatement0 = this.conn.prepareStatement("SELECT * FROM whitelist WHERE username = ? AND world = ?");
        preparedStatement0.setString(1, username);
        preparedStatement0.setString(2, Core.GameSaveWorld);
        ResultSet resultSet = preparedStatement0.executeQuery();
        boolean _boolean = resultSet.next();
        if (ban && !_boolean) {
            PreparedStatement preparedStatement1 = this.conn
                .prepareStatement("INSERT INTO whitelist (world, username, password, encryptedPwd) VALUES (?, ?, 'bogus', 'false')");
            preparedStatement1.setString(1, Core.GameSaveWorld);
            preparedStatement1.setString(2, username);
            preparedStatement1.executeUpdate();
            preparedStatement1.close();
            resultSet = preparedStatement0.executeQuery();
            _boolean = true;
        }

        if (_boolean) {
            String string0 = "true";
            if (!ban) {
                string0 = "false";
            }

            preparedStatement0.close();
            preparedStatement0 = this.conn.prepareStatement("UPDATE whitelist SET banned = ? WHERE username = ?");
            preparedStatement0.setString(1, string0);
            preparedStatement0.setString(2, username);
            preparedStatement0.executeUpdate();
            preparedStatement0.close();
            if (SteamUtils.isSteamModeEnabled()) {
                preparedStatement0 = this.conn.prepareStatement("SELECT steamid FROM whitelist WHERE username = ? AND world = ?");
                preparedStatement0.setString(1, username);
                preparedStatement0.setString(2, Core.GameSaveWorld);
                resultSet = preparedStatement0.executeQuery();
                if (resultSet.next()) {
                    String string1 = resultSet.getString("steamid");
                    preparedStatement0.close();
                    if (string1 != null && !string1.isEmpty()) {
                        this.banSteamID(string1, "", ban);
                    }
                } else {
                    preparedStatement0.close();
                }
            }

            return ban ? "User " + username + " is now banned" : "User " + username + " is now un-banned";
        } else {
            preparedStatement0.close();
            return "User \"" + username + "\" is not in the whitelist, use /adduser first";
        }
    }

    public String banIp(String ip, String username, String reason, boolean ban) throws SQLException {
        if (ban) {
            PreparedStatement preparedStatement0 = this.conn.prepareStatement("INSERT INTO bannedip (ip, username, reason) VALUES (?, ?, ?)");
            preparedStatement0.setString(1, ip);
            preparedStatement0.setString(2, username);
            preparedStatement0.setString(3, reason);
            preparedStatement0.executeUpdate();
            preparedStatement0.close();
        } else {
            if (ip != null) {
                PreparedStatement preparedStatement1 = this.conn.prepareStatement("DELETE FROM bannedip WHERE ip = ?");
                preparedStatement1.setString(1, ip);
                preparedStatement1.executeUpdate();
                preparedStatement1.close();
            }

            PreparedStatement preparedStatement2 = this.conn.prepareStatement("DELETE FROM bannedip WHERE username = ?");
            preparedStatement2.setString(1, username);
            preparedStatement2.executeUpdate();
            preparedStatement2.close();
        }

        return "";
    }

    public String banSteamID(String steamID, String reason, boolean ban) throws SQLException {
        if (ban) {
            PreparedStatement preparedStatement0 = this.conn.prepareStatement("INSERT INTO bannedid (steamid, reason) VALUES (?, ?)");
            preparedStatement0.setString(1, steamID);
            preparedStatement0.setString(2, reason);
            preparedStatement0.executeUpdate();
            preparedStatement0.close();
        } else {
            PreparedStatement preparedStatement1 = this.conn.prepareStatement("DELETE FROM bannedid WHERE steamid = ?");
            preparedStatement1.setString(1, steamID);
            preparedStatement1.executeUpdate();
            preparedStatement1.close();
        }

        return "";
    }

    public String setUserSteamID(String user, String steamID) {
        try {
            PreparedStatement preparedStatement = this.conn.prepareStatement("SELECT * FROM whitelist WHERE username = ?");
            preparedStatement.setString(1, user);
            ResultSet resultSet = preparedStatement.executeQuery();
            if (!resultSet.next()) {
                preparedStatement.close();
                return "User " + user + " not found";
            }

            preparedStatement.close();
            preparedStatement = this.conn.prepareStatement("UPDATE whitelist SET steamid = ? WHERE username = ?");
            preparedStatement.setString(1, steamID);
            preparedStatement.setString(2, user);
            preparedStatement.executeUpdate();
            preparedStatement.close();
        } catch (SQLException sQLException) {
            sQLException.printStackTrace();
        }

        return "User " + user + " SteamID set to " + steamID;
    }

    public void setPassword(String username, String password) throws SQLException {
        try {
            PreparedStatement preparedStatement = this.conn
                .prepareStatement("UPDATE whitelist SET pwdEncryptType = '2', password = ? WHERE username = ? and world = ?");
            preparedStatement.setString(1, password);
            preparedStatement.setString(2, username);
            preparedStatement.setString(3, Core.GameSaveWorld);
            preparedStatement.executeUpdate();
            preparedStatement.close();
        } catch (SQLException sQLException) {
            sQLException.printStackTrace();
        }
    }

    public void updateLastConnectionDate(String u, String p) {
        try {
            PreparedStatement preparedStatement = this.conn.prepareStatement("UPDATE whitelist SET lastConnection = ? WHERE username = ? AND password = ?");
            preparedStatement.setString(1, dateFormat.format(Calendar.getInstance().getTime()));
            preparedStatement.setString(2, u);
            preparedStatement.setString(3, p);
            preparedStatement.executeUpdate();
            preparedStatement.close();
        } catch (SQLException sQLException) {
            sQLException.printStackTrace();
        }
    }

    private static boolean isNullOrEmpty(String string) {
        return string == null || string.isEmpty();
    }

    public String addWarningPoint(String username, String reason, int amount, String issuedBy) throws SQLException {
        PreparedStatement preparedStatement = this.conn.prepareStatement("SELECT * FROM whitelist WHERE username = ? AND world = ?");
        preparedStatement.setString(1, username);
        preparedStatement.setString(2, Core.GameSaveWorld);
        ResultSet resultSet = preparedStatement.executeQuery();
        if (resultSet.next()) {
            this.addUserlog(username, Userlog.UserlogType.WarningPoint, reason, issuedBy, amount);
            return "Added a warning point on " + username + " reason: " + reason;
        } else {
            return "User " + username + " doesn't exist.";
        }
    }

    public void addTicket(String author, String message, int ticketID) throws SQLException {
        if (ticketID > -1) {
            PreparedStatement preparedStatement0 = this.conn.prepareStatement("INSERT INTO tickets (author, message, answeredID) VALUES (?, ?, ?)");
            preparedStatement0.setString(1, author);
            preparedStatement0.setString(2, message);
            preparedStatement0.setInt(3, ticketID);
            preparedStatement0.executeUpdate();
            preparedStatement0.close();
        } else {
            PreparedStatement preparedStatement1 = this.conn.prepareStatement("INSERT INTO tickets (author, message) VALUES (?, ?)");
            preparedStatement1.setString(1, author);
            preparedStatement1.setString(2, message);
            preparedStatement1.executeUpdate();
            preparedStatement1.close();
        }
    }

    public ArrayList<DBTicket> getTickets(String playerName) throws SQLException {
        ArrayList arrayList = new ArrayList();
        PreparedStatement preparedStatement = null;
        if (playerName != null) {
            preparedStatement = this.conn.prepareStatement("SELECT * FROM tickets WHERE author = ? and answeredID is null");
            preparedStatement.setString(1, playerName);
        } else {
            preparedStatement = this.conn.prepareStatement("SELECT * FROM tickets where answeredID is null");
        }

        ResultSet resultSet = preparedStatement.executeQuery();

        while (resultSet.next()) {
            DBTicket dBTicket0 = new DBTicket(resultSet.getString("author"), resultSet.getString("message"), resultSet.getInt("id"));
            arrayList.add(dBTicket0);
            DBTicket dBTicket1 = this.getAnswer(dBTicket0.getTicketID());
            if (dBTicket1 != null) {
                dBTicket0.setAnswer(dBTicket1);
            }
        }

        return arrayList;
    }

    private DBTicket getAnswer(int _int) throws SQLException {
        PreparedStatement preparedStatement = null;
        preparedStatement = this.conn.prepareStatement("SELECT * FROM tickets WHERE answeredID = ?");
        preparedStatement.setInt(1, _int);
        ResultSet resultSet = preparedStatement.executeQuery();
        return resultSet.next() ? new DBTicket(resultSet.getString("author"), resultSet.getString("message"), resultSet.getInt("id")) : null;
    }

    public void removeTicket(int ticketID) throws SQLException {
        DBTicket dBTicket = this.getAnswer(ticketID);
        if (dBTicket != null) {
            PreparedStatement preparedStatement0 = this.conn.prepareStatement("DELETE FROM tickets WHERE id = ?");
            preparedStatement0.setInt(1, dBTicket.getTicketID());
            preparedStatement0.executeUpdate();
            preparedStatement0.close();
        }

        PreparedStatement preparedStatement1 = this.conn.prepareStatement("DELETE FROM tickets WHERE id = ?");
        preparedStatement1.setInt(1, ticketID);
        preparedStatement1.executeUpdate();
        preparedStatement1.close();
    }

    public class LogonResult {
        public boolean bAuthorized = false;
        public int x;
        public int y;
        public int z;
        public boolean newUser = false;
        public boolean admin = false;
        public boolean banned = false;
        public boolean priority = false;
        public String bannedReason = null;
        public String dcReason = null;
        public String accessLevel = "";
        public int transactionID = 0;
    }
}
